﻿#region File and License Information
/*
<File>
	<License>
		Copyright © 2009 - 2017, Daniel Vaughan. All rights reserved.
		This file is part of Calcium (http://calciumsdk.net), 
		which is released under the MIT License.
		See file /Documentation/License.txt for details.
	</License>
	<CreationDate>2015-04-23 12:06:04Z</CreationDate>
</File>
*/
#endregion

using System;
using System.Globalization;
using System.Windows;
using System.Windows.Data;

using Microsoft.Phone.Controls;

namespace Outcoder.UI.Xaml.Converters
{
	/// <summary>
	/// Converts a <c>PageOrientation</c> value to a <c>Visibility</c> 
	/// value depending on the parameter, which must be supplied.
	/// For example, if the parameter equals 'landscape' (case insensitive) 
	/// and the PageOrientation is Landscape, Visibility.Visible is returned from the <c>Convert</c> method.
	/// </summary>
	public class PageOrientationToVisibilityConverter : IValueConverter
	{
		public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
		{
			if (parameter == null)
			{
				throw new ArgumentException("OrientationToVisibilityConverter parameter cannot be null.");
			}

			if (value == null)
			{
				return Visibility.Visible;
			}

			var orientation = (PageOrientation)value;

			string p = parameter.ToString().ToLowerInvariant();

			if (p == "landscape")
			{
				if (orientation.IsLandscape())
				{
					return Visibility.Visible;
				}
				return Visibility.Collapsed;
			}
			else if (p == "portrait")
			{
				if (orientation.IsLandscape())
				{
					return Visibility.Collapsed;
				}
				return Visibility.Visible;
			}
			else
			{
				throw new ArgumentException("OrientationToVisibilityConverter parameter has invalid value of " + parameter);
			}
		}

		public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
		{
			throw new NotImplementedException();
		}
	}
}
